package com.useeinfo.oa.modules.base.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.CommonSugar;
import com.useeinfo.framework.sugar.tools.StringConverters;

import javax.persistence.*;

/**
 * @Auther: xudong.sun
 * @Date: 2018/11/30 13:21
 * @Description: 设备分组
 */
@Entity
@Table(name = "facility_group")
public class FacilityGroup extends SuperClassEntity<FacilityGroup> {

    /**
     * 设备分组名称
     */
    private String facilityGroupName;
    /**
     * 设备分组编号
     */
    private String facilityGroupCode;
    /**
     * 描述
     */
    private String description;
    /**
     * 创建人ID
     */
    private Long systemUserId;
    /**
     * 创建人姓名
     */
    private String systemUserName;
    /**
     * 关联企业
     */
    @ManyToOne
    @JoinColumn(name = "enterprise_id")
    private Enterprise enterprise;

    public String getFacilityGroupName() {
        return facilityGroupName;
    }

    public void setFacilityGroupName(String facilityGroupName) {
        this.facilityGroupName = facilityGroupName;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    public String getFacilityGroupCode() {
        return facilityGroupCode;
    }

    public void setFacilityGroupCode(String facilityGroupCode) {
        this.facilityGroupCode = facilityGroupCode;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Long getSystemUserId() {
        return systemUserId;
    }

    public void setSystemUserId(Long systemUserId) {
        this.systemUserId = systemUserId;
    }

    public String getSystemUserName() {
        return systemUserName;
    }

    public void setSystemUserName(String systemUserName) {
        this.systemUserName = systemUserName;
    }

    @Override
    public JSONObject toJSONObject() {
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("facilityGroupName", StringConverters.null2String(getFacilityGroupName()));
        jsonObject.put("facilityGroupCode", StringConverters.null2String(getFacilityGroupCode()));
        jsonObject.put("description", StringConverters.null2String(getDescription()));
        jsonObject.put("systemUserId", CommonSugar.getTypedDefault(getSystemUserId(), 0L));
        jsonObject.put("systemUserName", StringConverters.null2String(getSystemUserName()));
        if(getEnterprise()!=null){
            jsonObject.put("enterpriseName", StringConverters.null2String(getEnterprise().getEnterpriseName()));
        }else{
            jsonObject.put("enterpriseName", "");
        }
        return jsonObject;
    }
}
